#include <byteswap.h>
#include <stdint.h>
#include <arpa/inet.h>
#include <type_traits>
#include <sys/types.h>

#include "byteendian.h"


namespace johnsonli
{
        //uint64_t 网络转本地
    unsigned long long ntohll(unsigned long long val)
    {
        if (__BYTE_ORDER == __LITTLE_ENDIAN)
        {
            return (((unsigned long long )htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32));
        }
        else if (__BYTE_ORDER == __BIG_ENDIAN)
        {
            return val;
        }
    }
    
    //uint64_t 本地转网络
    unsigned long long htonll(unsigned long long val)
    {
        if (__BYTE_ORDER == __LITTLE_ENDIAN)
        {
            return (((unsigned long long )htonl((int)((val << 32) >> 32))) << 32) | (unsigned int)htonl((int)(val >> 32));
        }
        else if (__BYTE_ORDER == __BIG_ENDIAN)
        {
            return val;
        }
    }



    uint16_t local_to_net16(uint16_t hostlong)
    {
        return htons(hostlong);
    }

    uint16_t net_to_local16(uint16_t netlong)
    {
        return ntohs(netlong);
    }

    uint32_t local_to_net32(uint32_t hostlong)
    {
        return htonl(hostlong);
    }

    uint32_t net_to_local32(uint32_t netlong)
    {
        return ntohl(netlong);
    }

    uint64_t local_to_net64(uint64_t hostlong)
    {
        return htonll(hostlong);
    }

    uint64_t net_to_local64(uint64_t netlong)
    {
        return ntohll(netlong);
    }

    


}
